#include<stdio.h>
struct fun
{
	int qishi;
	int changdu;
};
int main()
{
	int n;
	scanf("%d",&n);
	int arr[n];
	struct fun pd[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	int count=0;
	int t=0;
	for(int i=0;i<n;i++)
	{
		pd[t].qishi=i;
		while(arr[i+1]>arr[i])
		{
			i++;
			count++;
		}
		pd[t].changdu=count;
		t++;
		count=0;
	}
	struct fun jiaohuan;
	for(int i=0;i<t;i++)
	{
		for(int j=0;j<t-i;j++)
		{
			if(pd[j+1].changdu>pd[j].changdu)
			{
				jiaohuan=pd[j];
				pd[j]=pd[j+1];
				pd[j+1]=jiaohuan;
			}
		}
	 }
	 for(int a=pd[0].qishi;a<=pd[0].qishi+pd[0].changdu;a++)
	 {
	 	printf("%d ",arr[a]);
	 }
 } 
